package com.example.activiti.listener;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.example.activiti.component.MailComponent;

@Component("activitiListener")
public class ActivitiListener implements TaskListener,ExecutionListener {

	@Autowired
	MailComponent mailComponent;
	
	@Override
	public void notify(DelegateTask delegateTask) {
		// TODO Auto-generated method stub
		String eventName =  delegateTask.getEventName();
		 if ("create".endsWith(eventName)) {
            System.out.println("create=========");
        }else if ("assignment".endsWith(eventName)) {
            System.out.println("assignment========"+delegateTask.getAssignee());
            String assgin = delegateTask.getAssignee();
            System.out.println(delegateTask.getTaskDefinitionKey());
            System.out.println(delegateTask.getDescription());
//            delegateTask.
            mailComponent.sendMail("fang101056@outlook.com");
            
        }else if ("complete".endsWith(eventName)) {
            System.out.println("complete===========");
        }else if ("delete".endsWith(eventName)) {
            System.out.println("delete=============");
        }
	}

	@Override
	public void notify(DelegateExecution execution) {
		// TODO Auto-generated method stub
		String eventName =  execution.getEventName();
		 if ("start".endsWith(eventName)) {
            System.out.println("start=========");
        }else if ("end".endsWith(eventName)) {
            System.out.println("end========");

        }
	}
	
}
